# -*- coding: utf-8 -*-
"""
Created on Tue Nov  9 10:09:40 2021

@author: yu
功能：谁先简单的银行账户
需求：
1 银行扎根好，属性如下
用户名username
    账号 card_id
    余额 balance
2 执行的操作
    存款 deposit
    取款 withdraw
    转账 transfer
    记住流水 history
3 业务分析
    存，取，转：判断交易金额是否合法
    取，转：判断月是否足够
    转：涉及两个账户，先去后存，一笔钱两边用所有的交易发生后都需要记录对应的流水
"""
# class clerk():
# class user():
# class bank()
import datetime
# 库名.类名.方法名
from datetime import datetime
# 类名.方法名
from datetime import datetime as dt


# dt.方法名
class BankAccount:
    def __init__(self, username, card_id, balance, history_list):
        self.username = username
        self.card_id = card_id
        self.balance = balance
        # 存储交易流水
        self.history_list = history_list

    # 方法
    def is_legal_amount(self, amount):
        """
        功能：判断交易金额是否合法

        Parameters
        ----------
        amount : TYPE
            DESCRIPTION.

        Returns
        -------
        None.

        """
        if amount <= 0:
            return False
        # isinstance(maount,(float,int))
        # amount是float或int中一种类型
        if not isinstance(amount, (float, int)):
            return False
        return True

    # 方法
    def is_enough(self, amount):
        """
        功能：判断余额是否足够

        Parameters
        ----------
        amount : TYPE
            DESCRIPTION.

        Returns
        -------
        None.

        """
        if self.balance < amount:
            return False
        return True

    # 方法
    def get_time(self):
        """
        功能：获取交易时间

        Returns
        -------
        None.

        """
        now = dt.now()
        current_time = \
            now.strftime('%Y-%m-%d')
        return current_time

    def depoosit(self, amount):
        """


        Parameters
        ----------
        amount : TYPE
            DESCRIPTION.

        Returns
        -------
        None.

        """
        if self.is_legal_amount(amount) == False:
            print('交易金额非法，无法存款！')
            return
        # 完成存款操作
        self.balance += amount
        # 记录当前这笔流水
        log = '{}于{}存入{}元，账户余额{}元' \
            .format(self.username, self.get_time(), amount, self.balance)
        self.history_list.append(log)

    def widthdraw(self, amount):
        """
        功能：取款

        Parameters
        ----------
        amount : TYPE
            DESCRIPTION.

        Returns
        -------
        None.

        """
        if self.is_legal_amount(amount) == False or self.balance < amount:
            print('交易金额非法，无法存款！')
            # if self.balance<amount:
            #     print('交易失败，请重新交易！')
            return
        self.balance -= amount
        log = '{}于{}取出{}元，账户余额{}元' \
            .format(self.username, self.get_time, amount, self.balance)
        self.history_list.append(log)

    def tansfer(self, another, amount):
        """
        功能：两个账户转账

        Parameters
        ----------
        another : TYPE
            DESCRIPTION.
        amount : TYPE
            DESCRIPTION.

        Returns
        -------
        None.

        """
        if self.is_legal_amount(amount) == False:
            print()
            return
        if self.is_enough(amount) == False:
            print()
            return
        self.balance -= amount
        log = '{}于{}向{}转出{}元，账户余额{}元'.format(self.username, self.get_time(), another.username, amount, self.balance)
        self.history_list.append(log)

        def destory(self):
            """
            功能：銷戶功能

            Returns
            -------
            None.

            """
            if self.blance > 0:
                print('賬戶餘額不爲0，是否確定銷戶')
                x = input('是否銷戶：（y/n）:')
                if x == 'y':
                    
                    return
                else:
                    return

        # 方法
        def print_log(self):
            """
            功能：打印流水

            Returns
            -------
            None.

            """
            for log in self.history_list:
                print(log)

        def main():
            bank_A = BankAccount('Alice', '2019000', 2300)
            bank_B = BankAccount('Jack', '2019111', 1500)
            bank_A.deposit(2000)
            bank_B.widthdraw(200)
            print_log(bank_A)
            print_log(bank_B)

        if __name__ == '__main__':
            main()

    def deposit(self, param):
        pass
